package com.caibing.config.shiro.config;

import com.caibing.config.shiro.CustomRealm;
import org.apache.shiro.mgt.SecurityManager;
import org.apache.shiro.spring.web.ShiroFilterFactoryBean;
import org.apache.shiro.web.mgt.DefaultWebSecurityManager;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @description:shiro配置
 * @author: lbx
 * @create: 2018/7/10 11:01
 **/
@Configuration
public class ShiroConfig {

    /**
     * @description:Shiro过滤器
     * @author: lbx
     * @create: 2018/7/20 8:59
     */
    @Bean
    public ShiroFilterFactoryBean shirFilter(SecurityManager securityManager) {
        ShiroFilterFactoryBean shiroFilterFactoryBean = new ShiroFilterFactoryBean();
        // 必须设置 SecurityManager
        shiroFilterFactoryBean.setSecurityManager(securityManager);

        //设置拦截器

        return shiroFilterFactoryBean;
    }

    /**
     * @description:注入 securityManager
     * @author: lbx
     * @create: 2018/7/20 9:03 
     */
    @Bean
    public SecurityManager securityManager(){
        DefaultWebSecurityManager  securityManager = new DefaultWebSecurityManager();
        //设置realm
       // securityManager.setRealm(customRealm());
        return securityManager;
    }


    @Bean
    public CustomRealm customRealm() {
        return new CustomRealm();
    }
}
